<?php
/**
 * 
 * 轮播器信息
 * xysc users Version1.0
 * ==================================
 * Copy 2016-2017
 * Web:www.xjh7.com
 * ==================================
 * Author:xjh
 * Date:2016-4-28
 * model() 创建模型对象，静态
 * tableName() 返回表名
*/
class Turn extends CActiveRecord {
	public $page_list = array();//分页数组
	public $infos_count = 0;//统计查询个数
	/**
	 *返回当前模型对象的方法 
	 */
	public static function model($className = __CLASS__){
		return parent::model($className);
	}
	/**
	 * 返回当前表名
	 */
	public function tableName(){
		return '{{turn}}';
	}


	/**
	 *更新标签信息
	 */
	public function updateTurn($turn_id,$sort){
		$cmodel = new CCCModel();
		$_sql = "UPDATE {{turn}} SET turn_sort = $sort WHERE turn_id = $turn_id";
		$row = $cmodel->upd($_sql);
		return $row;
	}
	
	/**
	 * 新增标签
	 */
	public function addTurn($addTurn){
		if(!isset($addTurn['turn_url']) || empty($addTurn['turn_url'])){
			$addTurn['turn_url'] = '#';
		}
		$cmodel = new CCCModel();
		$_sql = "INSERT INTO {{turn}}(`turn_url`,`turn_sort`,`active`) VALUES ('".$addTurn['turn_url']."','".$addTurn['turn_sort']."','".$addTurn['active']."')";
		$row = $cmodel->upd($_sql);
		return $row;
	}

	
	/**
	 * 标签修改
	 */
	public function TurnUpdate($recPost,$turn_id){
		$cmodel = new CCCModel();
		if($recPost['send'] == "修改"){
			$_sql = "UPDATE {{turn}} set 
							turn_url='".$recPost['turn_url']."',
							turn_sort=".$recPost['sort'].",
							active=".$recPost['active']."
							WHERE turn_id=".$turn_id;
				$row = $cmodel->upd($_sql);
		}
		return $row;
	}

	/**
	 * 查找单条记录
	 */
	public function getTurnById($turn_id){
		$cmodel = new CCCModel();
		$_sql = "SELECT * FROM {{turn}} WHERE turn_id=".$turn_id;
		$result = $cmodel->sel($_sql);
		return $result;
	}
	
	/**
	 * 删除轮播
	 */
	public function TurnDel($turn_id){
		$cmodel = new CCCModel();
		$_sql = "DELETE from {{turn}} WHERE turn_id=".$turn_id;
		$row = $cmodel->upd($_sql);
		return $row;
	}
	/**
	 * 分页+搜索
	 */
	public function pageSearch($getInfo){
		$_sql = '';
		$cmodel = new CCCModel();
		$_sql .= "SELECT * FROM {{turn}} WHERE 1=1";
		$nextpage = "";
		if ($getInfo){     
			if($_POST['active'] != 3){
				$nextpage .= "/active=".$getInfo['active'];
				$_sql.=" AND active=".$getInfo['active'];
			}
			$_sql_count = str_replace('SELECT *','SELECT count(*)',$_sql);
		}
		
			$_sql .= " ORDER BY turn_sort ASC";
			$infos = $cmodel->sel($_sql);
	
			return $infos;
	}
	
	/**
	 * 按照sort查询所有数据
	 */
	public function all(){
		$all_model = new CCCModel();
		$_sql = "SELECT * FROM {{turn}}  ORDER BY turn_sort ASC ";
		$result = $all_model->sel($_sql);
		return $result;
	}

}
	
?>